<?php
declare(strict_types=1);

namespace App\Service;

use App\Constants\MchAccountRemarkMapping;
use App\Constants\StrStatus;
use App\Model\Enum\MchAccountAccessTypeEnum;
use App\Model\Enum\MchAccountInOutTypeEnum;
use App\Utils\CustomUtils;
use Hyperf\Contract\TranslatorInterface;
use Hyperf\Di\Annotation\Inject;
use App\Model\Dao\MchAccountAccessDetailDao;
use App\Exception\XZXValidationException;
use App\Constants\XZXResponseCode;
use Hyperf\Utils\ApplicationContext;
use Hyperf\Utils\Coroutine;
use App\Utils\DateUtils;


class MchAccountAccessDetailService
{
    /**
     * @Inject()
     * @var MchAccountAccessDetailDao
     */
    private $MchAccountAccessDetailDao;

    /**
     * @Inject
     * @var TranslatorInterface
     */
    private $translator;

    /**
     * @Inject()
     * @var MchAccountAccessService
     */
    private $MchAccountAccessService;

    public function list(array $param)
    {

        $limit = $param['limit'];
        $page = $param['page'];        

        $total = $this->MchAccountAccessDetailDao->getCount($param);
        $list = $this->MchAccountAccessDetailDao->getList($param, $page, $limit);

        $locale = $this->translator->getLocale();
        foreach ($list as $k => $v) {
            (isset($v['createTime']) && !empty($v['createTime'])) && $v['createTime'] = DateUtils::getMsecToMescdate($v['createTime']);
            $v['strInOutType'] = MchAccountInOutTypeEnum::getLabel($v['inOutType']);

            if (!empty($v['accessType'])) {
                $v['strAccessType'] = MchAccountAccessTypeEnum::getLabel($v['accessType']);
            } else {
                $v['strAccessType'] = MchAccountAccessTypeEnum::getLabel(substr(strval($v['type']), 0, 2) . '01');
            }

            if ($locale == 'en') {
                $v['remark'] = MchAccountRemarkMapping::REMARK[$v['remark']];
            }

            $this->MchAccountAccessService->strAccountType($param['source'], $v['accountType'], $v);
            $this->MchAccountAccessService->setSerialNo($v);
            $list[$k] = $v;
        }

        $data = array(
            'total' => $total,
            'list' => $list
        );

        return CustomUtils::xeServiceReturnData(XZXResponseCode::SUCCESS_CODE,XZXResponseCode::getMessage(XZXResponseCode::SUCCESS_CODE),$data);
    }    
}